//
//  BVMyVideoViewController.m
//  XiangYu
//
//  Created by YYKJ on 2017/6/15.
//  Copyright © 2017年 YYKJ. All rights reserved.
//

#import "BVMyVideoViewController.h"
#import "BVMySmallVideoCell.h"
#import "BVMyVideoAlertView.h"

#define BUY_INDEX_COLLECTIONVIEW_CELL1 @"BVMySmallVideoCell"

@interface BVMyVideoViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@property (nonatomic ,strong) UICollectionView              *collectionView;
@property (nonatomic ,strong) UICollectionViewFlowLayout    *layout;

@end

@implementation BVMyVideoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor BVBackgroundLightGrayColor]];
    [self.navigationItem setTitle:@"我的小视频"];
    
    [self layoutUI];
}

-(void)layoutUI{
    
    UICollectionViewFlowLayout *layout=[[ UICollectionViewFlowLayout alloc ] init];
    layout.headerReferenceSize=CGSizeMake(self.view.frame.size.width, 0);
    
    UICollectionView *collectionView = [[UICollectionView alloc ] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH-64) collectionViewLayout:layout];
    [self.view addSubview :collectionView];
    [collectionView setBackgroundColor:[UIColor clearColor]];
    [collectionView setDelegate:self];
    [collectionView setDataSource:self];
    
    [collectionView registerClass:[BVMySmallVideoCell class] forCellWithReuseIdentifier:BUY_INDEX_COLLECTIONVIEW_CELL1];
    
}

#pragma mark -- UICollectionViewDataSource ,UICollectionViewDelegate
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
    
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    BVMySmallVideoCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:BUY_INDEX_COLLECTIONVIEW_CELL1 forIndexPath:indexPath];
    if (indexPath.row == 0) {
        [cell.imgView setImage:[UIImage imageNamed:@"takePicture"]];
    }else{
        [cell.imgView setImage:[UIImage imageNamed:@"999k"]];
    }
    
    return cell;
    
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:( NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        
    }else{
        
        BVMyVideoAlertView *video = [[BVMyVideoAlertView alloc]init];
        [video showMKPAlertView];
        
    }
    NSLog(@"-----%ld",(long)indexPath.row);
    
}

-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
    
}

#pragma mark --UICollectionViewDelegateFlowLayout
//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:( UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:( NSIndexPath *)indexPath
{
    return CGSizeMake (ScreenW/3-5, ScreenW/3-5);
    
}

//定义每个UICollectionView 的边距
-(UIEdgeInsets )collectionView:( UICollectionView *)collectionView layout:( UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:( NSInteger )section
{
    return UIEdgeInsetsMake(2, 2, 2, 2);
}

//个是两行cell之间的间距（上下行cell的间距）
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 5;
}
//两个cell之间的间距（同一行的cell的间距）
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    
    return 5;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
